/*******************************************************************************
Replication Code for Research Article: 

Lanahan, L., A. Joshi, and E. Johnson. (2021) ‘Small Business Growth from Public R&D Funding: Evidence from a Natural Experiment of the SBIR/STTR Program’ Research Policy.

Paper Abstract: Governments make substantial investments in small businesses to promote innovation and create jobs. While there is extensive evidence that R&D policies catalyze innovation, there is less empirical evidence on their employment effects. We examine the impact of public R&D subsidies on net job creation with a two-study empirical research design that draws upon first-time recipients of the U.S. SBIR/STTR program from the five leading federal agencies from 2000 to 2015. This two-study design enables us to analyze the extensive and intensive margins of the program. For the first study, we compare federal recipients to a matched set of non-recipients and find awardees hire fewer employees than their counterparts. For the second study, we leverage a natural experiment to investigate the employment effects of additional matching funds from state governments. We find evidence that federal recipients that receive noncompetitive matching funds also hire fewer employees than federal recipients located in states without the match. We investigate a series of features that may accelerate or attenuate the total effect and find that ventures substitute away from hiring toward partnering and gaining access to external resources. Moreover, firms with heightened levels of risk, indicated by medium-to-low credit records, account for the greatest difference. These results highlight tensions for ventures as they balance competing expectations of the program to stimulate innovation while also creating jobs. Policymakers should reconsider whether emphasizing direct job growth is appropriate when evaluating this type of R&D program.

Notes about this code: This paper presents a two study design: Study 1 EXTENSIVE MARGIN; and Study 2 INTENSIVE MARGIN. Each study relied on a different dataset. 

Below details the code for the primary Figures and Tables presented in the research article. Please contact Lauren Lanahan (llanahan@uoregon.edu) for more information on the code pertaining to the results reported in the appendix.  
*******************************************************************************/
clear all
set more off
use "$dir\Harvard Dataverse_Study 1.dta"
********************************************************************************
* Figure 1 -- Extensive Margin TRENDS
********************************************************************************
{
preserve 
	drop if trend < -1
	gen emp_T = emp if treat == 1
	gen emp_C = emp if treat == 0
	twoway (lfitci emp_T trend, ciplot(rline) legend(label(2 "Treated")) yscale(range(3 7)) ylabel(3(1)7) xscale(range(-1 3)) xlabel(-1(1)3) mcolor(black) xline(0, lpattern(longdash) lcolor(gs13))) (lfitci emp_C trend, ciplot(rline) lcolor(red) legend(label(4 "Control")) mcolor(gs10) msymbol(S))
restore 
}
********************************************************************************
* Table 1 -- Extensive Margin DESCRIPTIVE STATISTICS
********************************************************************************
{
********************************************************************************
	* Table 1 (col 1 - 7) Panel A
********************************************************************************
preserve 
	keep if age_atSBIR == 1
	set more off
	global variables firstyear minority_women epscor Phase_I REG1 REG2 REG3 REG4 cluster_mean N3_541 N3_334 N3_325 N3_561 N3_339 N3_511 
	estpost tabstat $variables, by(treat) statistics(count mean p50 p25 p75 sd min max) columns(statistics)
restore 
preserve 
	keep if age_atSBIR == 1
	set more off
	global variables age_firstsbir phase1_total phase2_total 
	estpost tabstat $variables if treat == 1, statistics(count mean p50 p25 p75 sd min max) columns(statistics) 
restore 
********************************************************************************
	* Table 1 (col 1 - 7) Panel B
********************************************************************************
preserve 
	keep if age_1yrprior == 1
	set more off
	global variables cum_contract_amt_1m patents_ever_on sales_df_1m emp 
	estpost tabstat $variables, by(treat) statistics(count mean p50 p25 p75 sd min max) columns(statistics)
restore 
********************************************************************************
	* Table 1 (col 1 - 7) Panel C
********************************************************************************
preserve 
	keep if age_3yrpost == 1
	set more off
	global variables emp any_creditrating exit sales_df_1m patents_ever_on
	estpost tabstat $variables, by(treat) statistics(count mean p50 p25 p75 sd min max) columns(statistics)
restore 
********************************************************************************
	* Table 1 (col 8 & 9) Panel A
********************************************************************************
preserve 
keep if age_atSBIR == 1
	global x treat
	set more off
	global variables firstyear minority_women epscor Phase_I REG1 REG2 REG3 REG4 cluster_mean N3_541 N3_334 N3_325 N3_561 N3_339 N3_511 
	matrix m1=(1)
	matrix m2=(1)
	matrix m3=(1)
	matrix m4=(1)
	foreach x in $variables {
	set more off
	di "T-test of means for `x'"
	ttest `x', by($x) unequal
	matrix m1 = m1\(r(mu_1))
	matrix m2 = m2\(r(mu_2))
	matrix m3 = m3\(r(t))
	matrix m4 = m4\(r(p))
	}
	matrix q1 = (m1[2..16,1..1],m2[2..16,1..1],m3[2..16,1..1],m4[2..16,1..1])
	matrix colnames q1 = Control Treat t-stat p-value
	matrix rownames q1 = firstyear minority_women epscor Phase_I REG1 REG2 REG3 REG4 cluster_mean N3_541 N3_334 N3_325 N3_561 N3_339 N3_511 
	matrix drop m1 m2 m3 m4
	mat list q1
restore
********************************************************************************
	* Table 1 (col 8 & 9) Panel B
********************************************************************************
preserve 
keep if age_1yrprior == 1
	global x treat
	set more off
	global variables any_creditrating cum_contract_amt_1m patents_ever_on sales_df_1m emp
	matrix m1=(1)
	matrix m2=(1)
	matrix m3=(1)
	matrix m4=(1)
	foreach x in $variables {
	set more off
	di "T-test of means for `x'"
	ttest `x', by($x) unequal
	matrix m1 = m1\(r(mu_1))
	matrix m2 = m2\(r(mu_2))
	matrix m3 = m3\(r(t))
	matrix m4 = m4\(r(p))
	}
	matrix q1 = (m1[2..6,1..1],m2[2..6,1..1],m3[2..6,1..1],m4[2..6,1..1])
	matrix colnames q1 = Control Treat t-stat p-value
	matrix rownames q1 = any_creditrating cum_contract_amt_1m patents_ever_on sales_df_1m emp
	matrix drop m1 m2 m3 m4
	mat list q1
restore
********************************************************************************
	* Table 1 (col 8 & 9) Panel C
********************************************************************************
preserve 
keep if age_3yrpost == 1
	global x treat
	set more off
	global variables emp any_creditrating exit sales_df_1m patents_ever_on
	matrix m1=(1)
	matrix m2=(1)
	matrix m3=(1)
	matrix m4=(1)
	foreach x in $variables {
	set more off
	di "T-test of means for `x'"
	ttest `x', by($x) unequal
	matrix m1 = m1\(r(mu_1))
	matrix m2 = m2\(r(mu_2))
	matrix m3 = m3\(r(t))
	matrix m4 = m4\(r(p))
	}
	matrix q1 = (m1[2..6,1..1],m2[2..6,1..1],m3[2..6,1..1],m4[2..6,1..1])
	matrix colnames q1 = Control Treat t-stat p-value
	matrix rownames q1 = emp any_creditrating exit sales_df_1m patents_ever_on
	matrix drop m1 m2 m3 m4
	mat list q1
restore
}
********************************************************************************
* Table 2 -- Extensive Margin FIRM AND YEAR FIXED EFFECTS
********************************************************************************
{
global dd posttreat post treat
global controls contract_amt_1m Phase_I 
xtset firm_ID1 age 
foreach y in emp { 
xtreg `y' $dd $controls i.year if trend <=1, fe vce(cluster firm_ID1)
xtreg `y' $dd $controls i.year if trend <=3, fe vce(cluster firm_ID1)
}
}
********************************************************************************
* Table 4 -- Extensive Margin QUANTILE REGRESSION WITH FIRM AND YEAR FIXED EFFECTS
********************************************************************************
{
preserve 
keep if trend <= 3
xtset firm_ID1 age 
set seed 8675309
foreach y in emp ln_emp {
qregpd `y' posttreat post $controls, quantile(0.25)id(firm_ID1)fix(age)
qregpd `y' posttreat post $controls, quantile(0.5)id(firm_ID1)fix(age)
qregpd `y' posttreat post $controls, quantile(0.75)id(firm_ID1)fix(age)
qregpd `y' posttreat post $controls, quantile(0.90)id(firm_ID1)fix(age)
}
restore 
}
********************************************************************************
* Table 5 -- Extensive Margin HETEROGENEITY ANALYSES
********************************************************************************
{
preserve 
xtset firm_ID1 age 
keep if trend <=3 
** STTR v SBIR **
xtreg emp i.any_sttr##(posttreat post c.contract_amt_1m Phase_I i.year), fe vce(cluster firm_ID1)
** CLUSTER LEAD v CLUSTER LAG **
xtreg emp i.cluster_lead##(posttreat post c.contract_amt_1m Phase_I i.year), fe vce(cluster firm_ID1)
** APPLIED v CONTRACTS **
xtreg emp i.basic_strata##(posttreat post c.contract_amt_1m Phase_I i.year), fe vce(cluster firm_ID1)
** HIGH CREDIT v LOW CREDIT
xtreg emp i.credit_lead##(posttreat post c.contract_amt_1m Phase_I i.year), fe vce(cluster firm_ID1)
** YOUNGER v OLDER 
xtreg emp i.young_strata##(posttreat post c.contract_amt_1m Phase_I i.year), fe vce(cluster firm_ID1)
restore 
}
********************************************************************************
* Table 3 -- Intensive Margin FIRM AND YEAR FIXED EFFECTS 
********************************************************************************
{
clear all 
set more off
use "$dir\Harvard Dataverse_Study 2.dta"
global controls i.year contract_amt_1m cluster_mean anycredit 
global dd posttreat postSBIR Phase_I 
xtset firm_ID2 year
foreach y in emp { 
xtreg `y' $dd $controls if panel <= 1, fe vce(cluster firm_ID2)
xtreg `y' $dd $controls if panel <= 3, fe vce(cluster firm_ID2)
}
}
* Author of code: Lauren Lanahan (llanahan@uoregon.edu)
